﻿$(function () {
    ini_table();
});
//初始化表单数据
function ini_table() {
    jQuery(".tblContent").each(function () {
        jQuery(this).find("colgroup col").each(function (i) {
            var col = this;
            var colstyle = $(col).attr("style");
            $(col).parents(".tblContent").children("tbody").children("tr").each(function () {
                var $td = jQuery(jQuery(this).children("td").get(i));
                if (!$td.hasClass("nocol")) {
                    $td.addClass($(col).attr("class"));
                    if (colstyle != undefined) {
                        var tdstyle = $td.attr("style");
                        if (tdstyle != undefined) {
                            $td.attr("style", colstyle + tdstyle);
                        }
                        else {
                            $td.attr("style", colstyle);
                        }
                    }
                }
            });
        });
    });
}

//设置多选项框的值
function SetCheckValue(source) {
    var values = [];
    var $parent = $(source).parent();
    $parent.find("input[type=checkbox]").each(function () {
        if (this.checked) {
            values.push($(this).val());
            $(this).attr("checked", "checked");
        } else {
            $(this).removeAttr("checked");
        }
    });
    $parent.find("input[type=hidden]").val(values.join(","));
}

//清除指定的input的值
function CheckClearValue(source, selector) {
    var origin, temp;
    if (selector.indexOf("#") > 0) {
        origin = selector;
        temp = selector.replace("/\./g", "_") + "_temp";
    } else {
        origin = "input[name='" + selector + "']";
        temp = "#" + selector.replace(/\./g, "_") + "_temp";
    }
    if (source.checked) {
        $(temp).val($(origin).val());
        $(origin).val("");
    } else {
        $(origin).val($(temp).val());
        $(temp).val("");
    }
}

//本地上传图片预览
function LocalImagePreview(source) {
    var selector = $(source).attr("id").replace("_File", "");
    var imgSelector = "img." + selector.replace("#", "");
    if ($.browser.msie && ($.browser.version == "7.0" || $.browser.version == "8.0")) {
        var src = $(source).val();
        $(imgSelector).attr("src", "file:///" + src);
        var title = src.substring(src.lastIndexOf("\\") + 1);
        $(imgSelector).attr("title", title);
        $(imgSelector).tooltip({ content: '<span>' + title + '</span>', });
    } else {
        var objFile = source.files[0];//选择上传的文件
        var objFileReader = new FileReader();
        objFileReader.readAsDataURL(objFile);//Base64
        $(objFileReader).load(function () {
            $(imgSelector).attr("src", this.result);
            $(imgSelector).attr("title", objFile.name);
            $(imgSelector).tooltip({ content: '<span>' + objFile.name + '</span>', });
        });
    }
}